<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>
  </head>
  <body></body>
  <script>
    // 工厂函数创建对象
    function user(name, age) {
      return {
        // 当属性和值一样的时候可以只写其中一个
        name,
        age,
        show: function () {
          console.log(this.name + "-好好学习");
        },
        info() {
          console.log(`${this.name}的年龄是${this.age}`);
          
        },
      };
    }
    let xh = user("小灰", 18);
    xh.show();
    let xm = user("小美", 22);
    xm.show();
    xm.info();
  </script>
</html>
